<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户编辑</title> 
#@resources()
</head>	
<body>
	<div class="layui-container">
		<form class="layui-form" action="">
			<input type="hidden" name="user.id" value="#(user.id)" /> <!-- id -->
			<div class="layui-form-item">
				<label class="layui-form-label">用户账号</label>
				<div class="layui-input-block">
					<input type="text" name="user.account"  required lay-verify="required"
						placeholder="请输入用户账号" value="#(user.account)" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">用户名称</label>
				<div class="layui-input-block">
					<input type="text" name="user.name" required lay-verify="required"
						placeholder="请输入用户名称" value="#(user.name)" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">是否启用</label>
			    <div class="layui-input-block">
			      <input type="checkbox" id="chkenable" name="user.enable" #if(user.enable) checked="checked" #end  lay-skin="switch" lay-text="是|否"><div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>是</em><i></i></div>
			    </div>
			  </div>
			
		    <div class="edit-btns">
				<button class="layui-btn layui-btn-sm" lay-submit lay-filter="save">保存</button>
				<button class="layui-btn layui-btn-primary layui-btn-sm" @event="close" >取消</button> 
			</div>
		</form>
	</div>
	<script type="text/javascript">
		layui.use([ 'layer','form' ], function() {
			var layer = layui.layer;
			var form = layui.form;
			
			form.on('submit(save)', function(data){
				  //后台保存数据
				  data.field["user.enable"] = $("#chkenable").prop("checked");
				  $.post(ctx +"/user/save", data.field, function(ret){
					  if(ret.state == "ok"){
						  parent.events.search();//调用父页面的查询表格方法刷新数据
					      events.close();
					  }else{
						  layer.alert(ret.msg || "服务器异常")
					  }
				  })
			      return false;//阻止表单跳转
			});
			
			var events = {
			    close: function(){
			    	var index = parent.layer.getFrameIndex(window.name);  
			    	parent.layer.close(index); 
			    }
			};
			
			$('.layui-btn').on('click', function(){
			    var type = $(this).attr('@event');
			    events[type] ? events[type].call(this) : '';
			});
		});
	</script>
</body>
</html>